<?php
namespace app\api\model\foodcash;

use app\common\model\Table as TableModel;
use think\facade\Db;

class Table extends TableModel
{
    /**
     * 结算
     */
    public function pay()
    {
        foreach ($this->status['order_id'] as $item){
            $order = Order::get($item);
            if($order['pay_status']['value'] == 30){
                $order->collection();//面对面收款 - 结算
            }
        }
        return true;
    }
    
    /**
     * 清台
     */
    public function clear()
    {
        // 开启事务
        Db::startTrans();
        try {
            $this->save(['status' => 10]); //清台
            foreach ($this->status['order_id'] as $item){
                $order = Order::get($item);
                $order->save(['order_status' => 30]);
            }
            Db::commit();
            return true;
        } catch (\Exception $e) {
            Db::rollback();
            $this->error = $e->getMessage();
            return false;
        }
    }
}
